package com.strongdigit.ioc.beanannotation.multibean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.io.PrintStream;
import java.util.List;
import java.util.Map;

@Component
public class BeanInvoker {

    //这个例子是autowird的集合注入，可以自动注入所有实现了指定接口的类实例
    @Autowired
    private List<BeanInterface> list;

    @Autowired
    private Map<String, BeanInterface> map1;

    //当有多个类型满足时，可以使用Qualifier来指定使用哪个类型
    @Autowired
    @Qualifier("beanImplTwo")
    private BeanInterface beanInterface;

    public void say() {

        if (null != list) {
            System.out.println("list ...");
            for (BeanInterface bean : list) {
                System.out.println(bean.getClass().getName());
            }
        } else {
         System.out.println("list is null");
      }


        if (null != map1 && 0 != map1.size()) {
            System.out.println("this is map");
            for (Map.Entry<String, BeanInterface> entry : map1.entrySet()) {
                System.out.println("key:" + entry.getKey() + ";value:" + entry.getValue());
            }

        } else {
            System.out.println("map is null");
        }

        if(null!=beanInterface)
        {
            System.out.println("beanInterface is :"+beanInterface.getClass().getName());

        } else {
            System.out.println(("beanInterface is null"));
        }
    }
}
